<template>
  <div class="record-list-card">
    <div class="section-title">
      <span>病历列表</span>
      <div class="header-actions">
        <el-button type="primary" :icon="Plus" @click="$emit('edit', null)">新建病历</el-button>
        <el-button :icon="Download">导出</el-button>
      </div>
    </div>

    <el-table :data="records" style="width: 100%" stripe v-loading="loading">
      <el-table-column prop="patientName" label="患者姓名" min-width="100" />
      <el-table-column prop="patientId" label="病历号" width="120" />
      <el-table-column prop="gender" label="性别" width="80" />
      <el-table-column prop="age" label="年龄" width="80" />
      <el-table-column prop="bedNumber" label="床号" width="100" />
      <el-table-column prop="department" label="科室" min-width="120" />
      <el-table-column prop="diagnosis" label="诊断" min-width="150" />
      <el-table-column prop="doctor" label="主治医生" min-width="120" />
      <el-table-column prop="admissionDate" label="入院日期" width="120" />
      <el-table-column prop="lastUpdate" label="最后更新" width="150" />
      <el-table-column label="状态" width="100">
        <template #default="{ row }">
          <el-tag :type="getStatusType(row.recordStatus)" size="small">
            {{ row.statusText }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200" fixed="right">
        <template #default="{ row }">
          <el-button size="small" @click="$emit('view', row)">查看</el-button>
          <el-button size="small" type="primary" @click="$emit('edit', row)">编辑</el-button>
          <el-button size="small" type="danger" @click="$emit('delete', row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="empty-state" v-if="!loading && records.length === 0">
      <el-empty description="暂无病历记录" />
    </div>
  </div>
</template>

<script setup>
import { Plus, Download } from '@element-plus/icons-vue'

defineProps({
  records: {
    type: Array,
    default: () => []
  },
  loading: {
    type: Boolean,
    default: false
  }
})

defineEmits(['view', 'edit', 'delete'])

// 获取状态标签类型
const getStatusType = (status) => {
  const map = {
    'completed': 'success',
    'pending': 'warning',
    'urgent': 'danger'
  }
  return map[status] || 'info'
}
</script>

<style lang="scss" scoped>
.record-list-card {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  margin-bottom: 24px;
}

.section-title {
  font-size: 18px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.empty-state {
  padding: 40px 0;
}

// 响应式设计
@media (max-width: 768px) {
  .section-title {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    
    .header-actions {
      width: 100%;
      justify-content: flex-end;
    }
  }
}
</style>